﻿using MediatR;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.SlaughtsWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.SlaughtsWay
{
    public class AddSlaughtsCommandHandler : IRequestHandler<AddSlaughtsCommand, ApiResult<int>>
    {
        IBaseReponsitory<Slaughts> Slaughts;

        public AddSlaughtsCommandHandler(IBaseReponsitory<Slaughts> Slaughts)
        {
            this.Slaughts = Slaughts;
        }

        public async Task<ApiResult<int>> Handle(AddSlaughtsCommand request, CancellationToken cancellationToken)
        {
        
            await Slaughts.AddAsync(request.Slaughts);
            return new ApiResult<int>
            {
                Code = ApiEnum.Success,
                Message = "添加成功",
                Data = 1
            };
        }
    }
}
